import request from '@/utils/request'
const path = require('path')

const modules = {}
const files = require.context('./modules', false, /\.js$/)
files.keys().forEach(key => {
  const module = files(key).default
  if (module !== undefined) {
    modules[path.basename(key, '.js')] = module
  }
})

const install = Vue => {
  if (install.installed) return
  install.installed = true
  Object.defineProperties(Vue.prototype, {
    axios: {
      get() {
        return request
      }
    },
    $http: {
      get() {
        return modules
      }
    }
  })
}

export default install
